<?php
namespace App\Http\Controllers\Tag;

use App\Http\Controllers\Controller;
use App\Libraries\Decorator\Image\CoverDecorator;
use App\Models\Banner\Banner;
use App\Models\Tag\Tag;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Validator;


class TagController extends Controller{



    public function __construct(){}

    /**
     * 获取标签
     * @param Request $request
     * @param Tag $tag
     * @return \Illuminate\Http\JsonResponse
     */
    public function tags(Request $request, Tag $tag){
        $validator = Validator::make($request->all(), [
            'type' => 'required|json',
        ], [
            'type.required' => '10001',
            'type.json' => '10002',
        ]);
        if ($validator->fails()) {
            return $this->sendFailResponse(400, $validator->errors()->first());
        }
        $request['type'] = \GuzzleHttp\json_decode($request['type']);
		if(!is_array($request['type'])){
			$request['type'] = [$request['type']];
		}
        $data = $tag->selectRaw('id as tag_id, name, bg_color, text_color, type')->whereIn('type', $request['type'])->get();
        return $this->sendSuccessResponse($data);
    }
}